<?php
/**
 * 添加菜单
 * User: Administrator
 * Date: 2018\9\11 0011
 * Time: 17:00
 */

namespace app\Lib\Model\AdminAuth\AdminMenu;


use app\Lib\Exception\BlException;
use app\Lib\InterfaceIn\AdminAuth\AdminMenu\AddAdminMenuHandle;

class AddAdminMenu extends  AdminMenuBase implements AddAdminMenuHandle
{
    /**
     * 参数验证和数据整合
     * @return array
     * @throws BlException
     */
    private function check(){
        $model  = $this->getMenuDb();
        $data   =  $this->handleArray();
        $data[$model->_create_uid]  = $this->opUser->getUid();
        $data[$model->_create_time] = time();
        if(!$this->getValidate()->scene('add')->check($data)){
            throw new BlException($this->getValidate()->getError());
        }
        return $data;
    }

    /**
     * 添加菜单
     * @return bool
     * @throws BlException
     */
    public function run()
    {
        $data    =  $this->check();
        $model   =  $this->getMenuDb();
        $result  =  $model->insert($data);
        if(!$result){
            throw new BlException('操作失败');
        }
        return true;
    }

}